package com.ai.mapper.made;

import com.ai.entity.function.FunctionPO;
import com.ai.entity.function.FunctionVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author Mr.Chen
 * @since 2020-06-18
 */
@Repository
public interface FunctionMapper extends BaseMapper<FunctionPO> {

/*    @Select("SELECT " +
            "\tfunctions.id, " +
            "\tfunctions.code, " +
            "\tfunctions.nickname, " +
            "\tfunctions.type, " +
            "\tfunctions.state, " +
            "\tfunctions.num, " +
            "\tfunctions.spots spot " +
            "FROM " +
            "\tfunctions " +
            "\tLEFT JOIN camera_function ON functions.id = camera_function.function_id  " +
            "WHERE " +
            "\tNOT EXISTS ( SELECT 1 FROM camera_function cf WHERE cf.camera_id = #{cameraId} AND functions.id = cf.function_id )  " +
            "\tAND functions.state > 0  " +
            "\tAND functions.nickname LIKE #{nickname};")*/

    @Select("SELECT " +
            "\tfunctions.id, " +
            "\tfunctions.code, " +
            "\tfunctions.nickname, " +
            "\tfunctions.type, " +
            "\tfunctions.state, " +
            "\tfunctions.num, " +
            "\tfunctions.spots spot " +
            "FROM " +
            "\tfunctions " +
            "\tWHERE " +
            "\tNOT EXISTS ( SELECT 1 FROM camera_function cf WHERE  camera_id = #{cameraId} AND functions.id = cf.function_id )  " +
            "\tAND functions.nickname LIKE #{nickname}  " +
            "\tAND functions.state > 0 ")
    List<FunctionVO> functionUncheckedList(int cameraId, String nickname);

   /* @Select("SELECT " +
            "\tfunctions.id, " +
            "\tfunctions.code, " +
            "\tfunctions.nickname, " +
            "\tfunctions.type, " +
            "\tfunctions.state , " +
            "\tcamera_function.spots spot " +
            "FROM " +
            "\tfunctions " +
            "\tLEFT JOIN camera_function ON functions.id = camera_function.function_id  " +
            "WHERE " +
            "\tEXISTS ( SELECT 1 FROM camera_function cf WHERE cf.camera_id = #{cameraId} AND functions.id = cf.function_id )  " +
            "\tAND functions.state > 0  " +
            "\tAND functions.nickname LIKE #{nickname}  " +
            "\tORDER BY camera_function.num;")*/

    @Select("SELECT " +
            "\tfunctions.id, " +
            "\tfunctions.code, " +
            "\tfunctions.nickname, " +
            "\tfunctions.type, " +
            "\tcamera_function.state, " +
            "\tcamera_function.num , " +
            "\tcamera_function.spots  spot " +
            "FROM " +
            "\tfunctions " +
            "\tLEFT JOIN camera_function ON functions.id = camera_function.function_id  " +
            "WHERE " +
            "\tcamera_function.camera_id = #{cameraId}  " +
            "\tAND functions.state > 0  " +
            "\tAND functions.nickname LIKE #{nickname}  " +
            "ORDER BY " +
            "\tcamera_function.num;")
    List<FunctionVO> functionCheckedList(int cameraId, String nickname);

    @Select("SELECT nickname FROM functions WHERE type = #{functionType} ")
    String getNameByCode(String functionType);
}
